package com.yq.homework.day22;

import com.sun.org.apache.regexp.internal.REUtil;

import javax.print.DocFlavor;
import java.util.Arrays;
import java.util.Random;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/22 19:37
 */
public class Demo04 {
    public static void main(String[] args) {
        //随机生成字符串
        String[] s1 = new String[8];
        for (int i = 0; i < 8; i++) {
            String s2 = get();
            s1[i] = s2;
        }
        System.out.println(Arrays.toString(s1));
        String[] result = paixu(s1);
        System.out.println(Arrays.toString(result));

    }

    public static String get() {
        Random random = new Random();
        String s = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < 5; i++) {
            int r1 = random.nextInt(62);
            stringBuffer.append(s.charAt(r1));
        }
        return stringBuffer.toString();
    }

    public static String[] paixu(String[] s) {
        String temp;
        for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s.length - i - 1; j++) {
                char fir = s[j].charAt(0);
                char sec = s[j + 1].charAt(0);
                if (Character.toLowerCase(fir) > Character.toLowerCase(sec)) {
                    temp = s[j];
                    s[j] = s[j + 1];
                    s[j + 1] = temp;
                }
            }
        }
        return s;

    }
}
